﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using NLog.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ebusiness_Framework.LogCenter
{
    public static class LogcenterCenterWebApplicationBuilderExtentions
    {
        /// <summary>
        /// 日志中心
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static WebApplicationBuilder UseLogCenter(this WebApplicationBuilder builder)
        {
            var config = builder.Configuration;
            var conf = config["ASPNETCORE_ENVIRONMENT"];
            //3、加载nlog.config
            builder.WebHost.ConfigureAppConfiguration((context, builder) =>
            {
                if (conf == "Development")
                    NLogBuilder.ConfigureNLog($"nlog.config");
                else
                    NLogBuilder.ConfigureNLog($"nlog.{conf}.config");
            });

            //2、集成NLog
            builder.WebHost.UseNLog();
            return builder;
        }
    }
}
